package com.doradance.app.home;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.doradance.R;
import com.doradance.account.UrlCenter;
import com.doradance.account.utils.FragmentUtils;
import com.doradance.common.http.MyHttpRequest;
import com.doradance.entity.UpdataMemberEntity;
import com.doradance.entity.VipEntity;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.framework.httprequest.responsecallbacks.DataRequestListener;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import de.hdodenhof.circleimageview.CircleImageView;

public class VipRechargeActivity extends BaseActivity {

    @Bind(R.id.iv_vip_head)
    CircleImageView mIvVipHead;
    @Bind(R.id.tv_vip_name)
    TextView mTvVipName;
    @Bind(R.id.tv_vip_introduce)
    TextView mTvVipIntroduce;
    @Bind(R.id.fl_vip)
    FrameLayout mFlVip;
    @Bind(R.id.iv_user_logo)
    ImageView mIvUserLogo;
    String type =-1+"";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolsBar();
        initData();
        type = getIntent().getStringExtra("type");
    }

    private void initData() {
        MyHttpRequest request = new MyHttpRequest(this);
        request.get(UrlCenter.VIP, null, new DataRequestListener<VipEntity>(VipEntity.class) {
            @Override
            public void onSuccess(VipEntity o) {
                super.onSuccess(o);
                Glide.with(VipRechargeActivity.this).load(o.getCurrent().getIcon()).asBitmap().into(mIvUserLogo);
                if(!TextUtils.isEmpty(o.getAvatar())){
                    Glide.with(VipRechargeActivity.this).load(o.getAvatar()).asBitmap().dontAnimate().placeholder(R.mipmap.init_logo).into(mIvVipHead);
                }else{
                    Glide.with(VipRechargeActivity.this).load(R.mipmap.init_logo).asBitmap().dontAnimate().placeholder(R.mipmap.init_logo).into(mIvVipHead);
                }
                if(TextUtils.isEmpty(o.getNick_name())){
                    mTvVipName.setText(getString(R.string.default_name));
                }else{
                    mTvVipName.setText(o.getNick_name());
                }

                if (o.isOpen() == true) {
                    mTvVipIntroduce.setText(o.getCurrent().getExpire_at_text());
                } else {
                    mTvVipIntroduce.setText(getString(R.string.become_vip));
                }
                List<VipEntity.VipsBean> vips = o.getVips();
                VipRechargeListFragment vipRechargeListFragment = new VipRechargeListFragment(o.getCurrent().getName(), vips, o.isOpen(), o.isHighest(),type);
                FragmentUtils.replaceFragment(getSupportFragmentManager(), R.id.fl_vip, vipRechargeListFragment);
            }

//            @Override
//            public void enableProgress(boolean enableProgress) {
//                super.enableProgress(enableProgress);
//                if (enableProgress) {
//                    enableProgress(false);
//                }
//            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    private void initToolsBar() {
        getCustomToolbar().addLeftImageButton(R.mipmap.back, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!type.equals(-1+"")){
                    int a = Integer.parseInt(type);
                   CoursesDetailActivity.start(VipRechargeActivity.this,a);
                    finish();
                }else{
                    finish();
                }

            }
        });
        setTitle(R.string.vip_recharge);
    }
    public static void start(Activity activity,String type) {
        Intent intent = new Intent(activity, VipRechargeActivity.class);
        intent.putExtra("type",type);
        activity.startActivity(intent);
    }

    public static void start(Context context,String type) {
        Intent intent = new Intent(context, VipRechargeActivity.class);
        intent.putExtra("type",type);
        context.startActivity(intent);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_vip_recharge, null);
    }

    /**
     * 监听Back键按下事件,方法1:
     * 注意:
     * super.onBackPressed()会自动调用finish()方法,关闭
     * 当前Activity.
     * 若要屏蔽Back键盘,注释该行代码即可
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();

    }


}
